package com.captainbank.tcl.tclapplication.utils;

import com.captainbank.tcl.tclapplication.application.TclApplication;
import com.captainbank.tcl.tclapplication.model.PersonDB;
import com.captainbank.tcl.tclapplication.model.PersonDBDao;
import com.captainbank.tcl.tclapplication.model.SkillDB;

import java.util.List;

/**
 * Created by TCL on 2019/10/15.
 * Describe:
 */
public class GreendaoUtil {
    //增
    public static void addPerson(PersonDB personDB) {
        TclApplication.getDaoSession().getPersonDBDao().insertOrReplace(personDB);
    }

    public static void addSkill(SkillDB skillDB) {
        TclApplication.getDaoSession().getSkillDBDao().insertOrReplace(skillDB);
    }

    //删
    public static void delPerson(long id) {
        TclApplication.getDaoSession().getPersonDBDao().deleteByKey(id);
    }

    //改
    public static void updatePerson(PersonDB personDB) {
        TclApplication.getDaoSession().getPersonDBDao().update(personDB);
    }

    //查
    public static List<PersonDB> queryPersonById(long id) {
        return TclApplication.getDaoSession().getPersonDBDao().queryBuilder().where(PersonDBDao.Properties.Id.eq(id)).list();
    }

    public static SkillDB querySkill() {
        return TclApplication.getDaoSession().getSkillDBDao().queryBuilder().unique();
    }

    public static List<PersonDB> queryPersonAll() {
        return TclApplication.getDaoSession().getPersonDBDao().loadAll();
    }

}
